/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package homebudget;

import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * @author Krit
 */
public class Entry {

    public String name;
    double wartosc;
    public double price;
    public double quantity;
    public String category;
    public String nameProduct;
    NumberFormat nf = NumberFormat.getInstance();

    public String getNameProduct() {
        return nameProduct;
    }

    public void setNameProduct(String nameProduct) {
        this.nameProduct = nameProduct;
    }
    public String categoryProduct;
    public String shop;    //to poprawic, bo chamskie jest
    public Date date;

    public String getCategory() {
        return category;
    }

    public void setCategory(String category) {
        this.category = category;
    }

    public String getCategoryProduct() {
        return categoryProduct;
    }

    public void setCategoryProduct(String categoryProduct) {
        this.categoryProduct = categoryProduct;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public double getQuantity() {
        return quantity;
    }

    public void setQuantity(double quantity) {
        this.quantity = quantity;
    }

    public String getShop() {
        return shop;
    }

    public void setShop(String shop) {
        this.shop = shop;
    }

    public double getWartosc() {
        return wartosc;
    }

    public void setWartosc(double wartosc) {
        this.wartosc = wartosc;
    }
    public static final SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, ''yy");


    //TODO w jakis sposob zmienic date...
    //TODO: w jakis sposob dodac produkty ze spacjami... pewnie trzeba je bedzie oddzielic ;
    //TODO: dodac sklep
    public Entry(String s, String c) {
        String[] entry = s.split(" ");
        this.name = entry[0];
        this.price = Float.parseFloat(entry[1]);

        if (entry.length == 3) {
            this.quantity = Integer.parseInt(entry[2]);
        } else {
            this.quantity = 1;
        }

        this.category = c;
        date = new Date();

    }
    
    public Entry(String s, String c, String shop) {
        String[] entry = s.split(" ");
        this.name = entry[0];
        this.price = Float.parseFloat(entry[1]);

        if (entry.length == 3) {
            this.quantity = Integer.parseInt(entry[2]);
        } else {
            this.quantity = 1;
        }

        this.category = c;
        this.shop = shop;
        date = new Date();

    }

    public Entry(){
        
    }

    //TODO: pewnie to pousuwac...
    /*
    public Entry(String s, float f) {
        this.name = s;
        this.price = f;
        quantity = 1;
        date = new Date();
    }

    public Entry(String s, float f, int q) {
        this.name = s;
        this.price = f;
        quantity = q;
        date = new Date();
    }*/

    public String getString() {
        String s = new String();
        nf.setMinimumFractionDigits(2);

        s += "      \""+nameProduct + "\", za: \"" + nf.format(price) + "zl\", ";
        if (quantity != 1) {
            s +=  "ilosc: \"" + nf.format(quantity) + "\",";
        }
           
        s += " \"" + category+"\", ";
        if(!shop.isEmpty()) {
            s += " \"" + shop+"\", ";
        }
        s += " \"" + sdf.format(date)+"\"";
        

        return s;
    }


}
